package cn.edu.zafu.bigdata.smj.a;

public class ArrayElement {
    public static int getElement(int[] arr, int index) {
        if (index < 0 || index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("索引超出数组范围: " + index);
        }
        return arr[index];
    }

    public static void main(String[] args) {
        try {
            int[] myArr = {1, 2, 3, 4, 5};
            int element = getElement(myArr, 5);
            System.out.println("元素是: " + element);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("错误: " + e.getMessage());
        }
    }
}